<template>
    <el-dialog :visible.sync="visible" title="修改职位信息" width="500px" @close="handleClose">
      <el-form ref="formRef" :model="formData" :rules="rules" label-width="100px">
        <el-form-item label="职位名称" prop="jobName">
          <el-input v-model="formData.jobName" placeholder="请输入职位名称"></el-input>
        </el-form-item>
        <el-form-item label="专业限制" prop="demand">
          <el-input v-model="formData.demand" placeholder="请输入专业限制"></el-input>
        </el-form-item>
        <el-form-item label="职位要求" prop="jobRequire">
          <el-input v-model="formData.jobRequire" placeholder="请输入职位要求"></el-input>
        </el-form-item>

        <el-form-item label="最低薪资" prop="minSalary">
          <el-input v-model="formData.minSalary" :min="0" placeholder="请输入最低薪资"></el-input>
        </el-form-item>
        <el-form-item label="最高薪资" prop="maxSalary">
          <el-input v-model="formData.maxSalary" :min="0" placeholder="请输入最高薪资"></el-input>
        </el-form-item>
        <el-form-item label="工作地址" prop="jobAddress">
          <el-input v-model="formData.jobAddress" placeholder="请输入工作地址"></el-input>
        </el-form-item>
        <el-form-item label="福利" prop="jobBenefits">
          <el-input v-model="formData.jobBenefits" placeholder="请输入福利"></el-input>
        </el-form-item>

        <!-- <el-form-item label="招聘状态" prop="jobStatus">
          <el-input v-model="formData.jobStatus" placeholder="数字(1:在招 2:停止招聘 其他数字:未知状态)"></el-input>
        </el-form-item> -->



        <el-form-item label="职位描述" prop="jobDescribe">
          <el-input v-model="formData.jobDescribe" type="textarea" placeholder="请输入职位描述"></el-input>
        </el-form-item>
        

      </el-form>
  
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleSubmit">保存</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  export default {
    props: {
      visible: Boolean,
      recruitData: Object, // 当前职位数据
    },
    data() {
      return {
        formData: {
          jobName: "",
          jobDescribe: "",
          minSalary: null,
          maxSalary: null,
          jobAddress: "",
          jobBenefits: "",
        //   jobStatus:0,
          demand:"",
          jobRequire: "",
        },
        rules: {
          jobName: [{ required: true, message: "请输入职位名称", trigger: "blur" }],
          minSalary: [{ required: true, message: "请输入最低薪资", trigger: "blur" }],
          maxSalary: [{ required: true, message: "请输入最高薪资", trigger: "blur" }],
          jobAddress: [{ required: true, message: "请输入工作地址", trigger: "blur" }],
        //   jobStatus: [{ required: true, message: "请输入招聘状态", trigger: "blur" }],
        },
      };
    },
    watch: {
      recruitData: {
        immediate: true,
        handler(newVal) {
          if (newVal) {
            this.formData = { ...newVal }; // 深拷贝职位数据
          }
        },
      },
    },
    methods: {
      handleClose() {
        this.$emit("update:visible", false); // 关闭对话框
      },
      handleSubmit() {
        this.$refs.formRef.validate((valid) => {
          if (valid) {
            this.$emit("submit", this.formData); // 提交修改后的数据
            this.handleClose(); // 关闭对话框
          } else {
            this.$message.warning("请填写完整信息！");
          }
        });
      },
    },
  };
  </script>
  
  <style scoped>
  .dialog-footer {
    text-align: right;
  }
  </style>